<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
    Object.defineProperty
     */
     var obj = {
       a: 10
     };
     var value = 100;
     Object.defineProperty(obj,'a', {
       get:function(){
        /* 
        getter
        拦截器
        拦截器了 对象a属性 获取值操作
        */
        return value;
       },
       set:function(newVal){
        // console.log('设置值', newVal)
         value = newVal;
        /* 
        setter 
        设置 对象 a属性的拦截器
        */
       }
     })
     console.log(obj.a);
     obj.a = 300;
     console.log(obj.a);
  </script>
</body>
</html>